package com.smashcrush.server.rest;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Variant;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.springframework.stereotype.Component;

@Provider
@Component
public class RestExceptionMapper implements ExceptionMapper<Throwable> {

	public Response toResponse(Throwable exception) {
		exception.printStackTrace();
		String a = "{\"java.lang.Throwable\":\"" + exception.getMessage()
				+ "\"}";

		return Response.status(500).variants(
				Variant.mediaTypes(MediaType.APPLICATION_JSON_TYPE).build())
				.entity(a).build();
	}

}